﻿package plugin.chatflash.component
{
    import __AS3__.vec.*;
    import flash.display.*;
    import flash.events.*;
    import morn.core.components.*;
    import plugin.chatflash.model.*;

    public class BugleChatPanel extends Sprite
    {
        private var mTextList:Vector.<BugleText>;
        private var mBugleList:Vector.<ChatVO>;
        public var backimg:Image;

        public function BugleChatPanel()
        {
            mouseEnabled = false;
            mouseChildren = false;
            this.mTextList = new Vector.<BugleText>;
            this.mBugleList = new Vector.<ChatVO>;
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_2:BugleText = null;
            var _loc_1:int = 0;
            while (_loc_1 < 3)
            {
                
                _loc_2 = new BugleText();
                _loc_2.y = 26 * _loc_1;
                addChild(_loc_2);
                this.mTextList.unshift(_loc_2);
                _loc_1++;
            }
            return;
        }// end function

        public function addBugle(param1:ChatVO) : void
        {
            this.mBugleList.push(param1);
            var _loc_2:int = 0;
            while (_loc_2 < this.mTextList.length)
            {
                
                if (!this.mTextList[_loc_2].showing)
                {
                    this.showBugle(this.mTextList[_loc_2]);
                    break;
                }
                _loc_2++;
            }
            return;
        }// end function

        private function showBugle(param1:BugleText) : void
        {
            if (this.mBugleList.length > 0)
            {
                param1.addEventListener("complete", this.completeHandler);
                param1.showBugle(this.mBugleList.shift().TalkContent);
                this.backimg.visible = true;
            }
            return;
        }// end function

        private function completeHandler(event:Event) : void
        {
            var _loc_2:* = event.currentTarget as BugleText;
            _loc_2.removeEventListener("complete", this.completeHandler);
            this.showBugle(_loc_2);
            this.backimg.visible = false;
            return;
        }// end function

    }
}
